//
//  AllMovieDetailView.m
//  newDouban
//
//  Created by dllo on 15/10/27.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "AllMovieDetailView.h"

@interface AllMovieDetailView ()



@property (nonatomic, retain) UILabel *rating;
@property (nonatomic, retain) UILabel *rating_count;
@property (nonatomic, retain) UILabel *date;
@property (nonatomic, retain) UILabel *runtime;
@property (nonatomic, retain) UILabel *genres;
@property (nonatomic, retain) UILabel *country;

@property (nonatomic, retain) UILabel *actorsTitle;
@property (nonatomic, retain) UILabel *plotTitle;
@property (nonatomic, retain) UILabel *actors;
@property (nonatomic, retain) UILabel *plot;
@property (nonatomic, retain) UIScrollView *scrollV;

@end

@implementation AllMovieDetailView




- (void)dealloc
{
    [_rating release];
    [_rating_count release];
    [_date release];
    [_runtime release];
    [_genres release];
    [_country release];
    [_actors release];
    [_plot release];
    [_movielcon release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    
    return self;
}

- (void)createSubviews
{
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 414, 736 - 64 - 49)];
    self.scrollV.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.scrollV];
    [_scrollV release];
    
    self.scrollV.contentSize = CGSizeMake(self.frame.size.width, 1200);
    
    
    self.movielcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.origin.x + 20, self.frame.origin.y + 40, (self.frame.size.width - 2 * 20) / 3, 190)];
    self.backgroundColor = [UIColor whiteColor];
    //self.movielcon.image = [UIImage imageNamed:@"h6.jpg"];
    [self.scrollV addSubview:self.movielcon];
    [_movielcon release];
    
    self.rating = [[UILabel alloc] initWithFrame:CGRectMake(self.movielcon.frame.origin.x + self.movielcon.frame.size.width + 30, self.frame.origin.y + 40, 80, 30)];
    self.rating.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.rating];
    [_rating release];
    //self.rating.text = @"评分: 7.1";
    self.rating.font = [UIFont boldSystemFontOfSize:18.0];
    
    self.rating_count = [[UILabel alloc] initWithFrame:CGRectMake(self.rating.frame.origin.x + self.rating.frame.size.width + 10, self.frame.origin.y + 40, 100, 30)];
    self.rating_count.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.rating_count];
    [_rating_count release];
    //self.rating_count.text = @"(4925评论)";
    self.rating_count.font = [UIFont boldSystemFontOfSize:18.0];
    
    
    
    self.date = [[UILabel alloc] initWithFrame:CGRectMake(self.movielcon.frame.origin.x + self.movielcon.frame.size.width + 30, self.rating.frame.origin.y + 40, 120, 30)];
    self.date.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.date];
    [_date release];
    //self.date.text = @"20140901";
    self.date.font = [UIFont boldSystemFontOfSize:18.0];
    
    
    self.runtime = [[UILabel alloc] initWithFrame:CGRectMake(self.movielcon.frame.origin.x + self.movielcon.frame.size.width + 30, self.date.frame.origin.y + 40, 120, 30)];
    self.runtime.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.runtime];
    [_runtime release];
    //self.runtime.text = @"126 min";
    self.runtime.font = [UIFont boldSystemFontOfSize:18.0];
    
    
    self.genres = [[UILabel alloc] initWithFrame:CGRectMake(self.movielcon.frame.origin.x + self.movielcon.frame.size.width + 30, self.runtime.frame.origin.y + 40, 150, 30)];
    self.genres.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.genres];
    [_genres release];
    //self.genres.text = @"动作/冒险/惊悚";
    self.genres.font = [UIFont boldSystemFontOfSize:18.0];
    
    
    self.country = [[UILabel alloc] initWithFrame:CGRectMake(self.movielcon.frame.origin.x + self.movielcon.frame.size.width + 30, self.genres.frame.origin.y + 40, 120, 30)];
    self.country.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.country];
    [_country release];
    //self.country.text = @"美国|法国";
    self.country.font = [UIFont boldSystemFontOfSize:18.0];
    
    self.actorsTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.origin.x + 30, self.movielcon.frame.origin.y + self.movielcon.frame.size.height + 10, 90, 50)];
    self.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.actorsTitle];
    [_actorsTitle release];
    self.actorsTitle.text = @"制作人";
    self.actorsTitle.font = [UIFont boldSystemFontOfSize:22.0];
    
    self.actors = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.origin.x + 30, self.actorsTitle.frame.origin.y + self.actorsTitle.frame.size.height + 10, self.frame.size.width - 2 * 30, 50)];
    self.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.actors];
    [_actors release];
    //self.actors.text = @"西尔维斯特-史泰龙 Sylvestre Stallone,杰森-斯坦森Jason Statham,梅尔-吉布斯Mel Gibson,李连杰JetLi";
    self.actors.font = [UIFont boldSystemFontOfSize:19.0];
    self.actors.numberOfLines = 0;
    //[self.actors sizeToFit];
    

    self.plotTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.origin.x + 30, self.actors.frame.origin.y + self.actors.frame.size.height + 30, 100, 50)];
    self.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.plotTitle];
    [_plotTitle release];
    self.plotTitle.text = @"电影情节";
    self.plotTitle.font = [UIFont boldSystemFontOfSize:22.0];
    
    self.plot = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.origin.x + 30, self.plotTitle.frame.origin.y + self.plotTitle.frame.size.height + 20, self.frame.size.width - 2 * 30, 50)];
    self.backgroundColor = [UIColor whiteColor];
    [self.scrollV addSubview:self.plot];
    [_plot release];
    //self.plot.text = @"     在此次第三部的故事中,巴尼(史泰龙饰) 与克里斯马斯(杰森-斯坦森 饰) 领衔的敢死队将正面迎战昔日战友,如今的军火枭雄看电视;联发科;安康;盛大开放;拉萨的开发;撒大家看法;阿斯顿尽快付款可怜的经典设计方式登记方式的发生发生的";
    self.plot.font = [UIFont boldSystemFontOfSize:19.0];
    self.plot.numberOfLines = 0;
    //[self.plot sizeToFit];
    
    //NSLog(@"========================================================================%f", self.plotTitle.frame.origin.y);

}


- (void)setMovieDt:(MovieDetail *)movieDt
{
    if (_movieDt != movieDt) {
    
        [_movieDt release];
        _movieDt = [movieDt retain];
    
    }
    
    self.rating.text = self.movieDt.rating;//@"评分: 7.1";
    NSString *rating_count = [NSString stringWithFormat:@"(%@评论)", self.movieDt.rating_count];
    self.rating_count.text = rating_count;//@"(4925评论)";
    self.date.text = self.movieDt.release_date;//@"20140901";
    self.runtime.text = self.movieDt.runtime;//@"126 min";
    self.genres.text = self.movieDt.genres;//@"动作/冒险/惊悚";
    self.country.text = self.movieDt.film_locations;//@"美国|法国";
    //self.actorsTitle.text = //@"制作人";
    self.actors.text = self.movieDt.actors;
    CGFloat actorsHeight = [AllMovieDetailView heightForContent:self.movieDt.actors width:414 - 60];
    CGRect actorsFrame = self.actors.frame;
    actorsFrame.size.height = actorsHeight;
    self.actors.frame = actorsFrame;
    [self.actors sizeToFit];
    

    self.plot.text = self.movieDt.plot_simple;
    CGFloat plotHeight = [AllMovieDetailView heightForContent:self.movieDt.plot_simple width:414 - 60];
    CGRect plotFrame = self.plot.frame;
    plotFrame.size.height = plotHeight;
    self.plot.frame = plotFrame;
    [self.plot sizeToFit];
    
    NSLog(@"plotHeight == %f", plotHeight);
    //自定义scrollV高度
    //activityDTV.scrollV.backgroundColor = [UIColor orangeColor];
    self.scrollV.contentSize = CGSizeMake(414, plotHeight + 420);
    
//    CGRect frameA = activityDTV.address.frame;
//    frameA.size.width = 414 - 180;
//    frameA.size.height = 45;
//    activityDTV.address.frame = frameA;
    
    
    
}


+ (CGFloat)heightForContent:(NSString *)content width:(CGFloat)width
{
    /**
     *  参数1.设置计算高度按照什么样的size来计算 注意::宽度一定要与label宽度一样,高度尽量大一些
     *  参数2.设置计算类型
     *  参数3.设置计算内容按照多大的字体计算 注意::字体大小也要跟label字体一样(label默认字体大小为17.0)
     *  参数4.系统备用参数,设置为nil
     *
     */
    CGSize size = CGSizeMake(width, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:19.0], NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    
    
    
    return frame.size.height;
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
